home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / gui4cli / g4c / rep.gc < prev    next >
Text File  |  1999-04-29  |  6KB  |  263 lines

  1. G4C
  2.  
  3. ; Rep.gc 1.3 (D.Kelesekis 29/9/97)
  4. ; =================================================================
  5.  
  6. ; This is a GUI script for the "Rep" command, which replaces strings
  7. ; in text files.
  8.  
  9.  
  10. ; =================================================================
  11.  
  12. ;                       The window & graphics
  13.  
  14. ; =================================================================
  15.  
  16. WINBIG 121 11 415 189 'Replace - SYS:'
  17. WinType 11110001  ; it's resizable & font sensitive with all gadgets
  18. varpath ''
  19.  
  20. BOX 0 0 415 189 OUT button
  21. BOX 210 28 195 77 in button
  22. BOX 210 109 196 37 IN BUTTON
  23. BOX 210 150 196 36 in button
  24.  
  25. CTEXT 219 30 "String:" #screen 8 2 0 "0001"
  26. CTEXT 218 58 "To String:" #screen 8 2 0 "0001"
  27. CTEXT 218 114 "Save to Dir:" #screen 8 2 0 "0001"
  28.  
  29. XICON 329 8 :rep.gc
  30. ezreq 'REP 1.3 - October 1997\n\nBy D.Keletsekis\ndck@prometheus.hol.gr\n' 'My Hero!' ''
  31.  
  32. ; =================================================================
  33.  
  34. ;                       System events
  35.  
  36. ; =================================================================
  37.  
  38. xOnLoad
  39. from   = ""
  40. to     = ""
  41. todir  = ram:
  42. savetodir = ON
  43. ci     = ""
  44. guiopen rep.gc
  45. ifexists file c:rep
  46.    RUN 'resident c:Rep pure add'
  47. elseifexists file guis:c/rep
  48.    RUN 'resident guis:c/Rep pure add'
  49. else
  50.    extract rep.gc guipath path
  51.    joinfile $path rep path
  52.    ifexists file $path
  53.        RUN 'resident $path pure add'
  54.    else
  55.        ezreq 'REP was not found!' OK ''
  56.    endif
  57. endif
  58. ; helper gui
  59. ifexists file guis:tools/rtn/filepop
  60.    helper = 1   ; set flag to know we have it
  61. else
  62.    helper = 0
  63. endif
  64.  
  65.  
  66. xOnClose
  67. guiquit rep.gc
  68. run 'resident rep remove'
  69.  
  70. ; =================================================================
  71.  
  72. ;                       The Directory listview
  73.  
  74. ; =================================================================
  75.  
  76. XLISTVIEW 6 5 198 182 "" file SYS: 10 DIR
  77. GadID 1
  78. gadhelp 'Select files to act upon'
  79. GadFont #mono 8 000
  80. if $helper = 1
  81.    guiload guis:tools/rtn/filepop $rep.gc/file   
  82. endif
  83.  
  84. xlvdirhook 1
  85. setwintitle rep.gc '$$lv.dir'
  86.  
  87.  
  88. ; =================================================================
  89.  
  90. ;                       The listview's buttons
  91.  
  92. ; =================================================================
  93.  
  94. XBUTTON 216 7 20 14 P
  95. gadhelp 'CD to Parent dir'
  96. lvuse rep.gc 1
  97. lvdir parent
  98. setwintitle rep.gc '$$lv.dir'
  99.  
  100. XBUTTON 237 7 20 14 D
  101. gadhelp 'Show Device list'
  102. lvuse rep.gc 1
  103. lvdir disks
  104. setwintitle rep.gc '$$lv.dir'
  105.  
  106. XBUTTON 261 7 20 14 A
  107. gadhelp 'Select all items'
  108. lvuse rep.gc 1
  109. lvdir all
  110.  
  111. XBUTTON 282 7 21 14 N
  112. gadhelp 'Unselect all items'
  113. lvuse rep.gc 1
  114. lvdir none
  115.  
  116.  
  117. ; =================================================================
  118.  
  119. ;               Settings - xTEXTIN & xCYCLER gadgets
  120.  
  121. ; =================================================================
  122.  
  123. XTEXTIN 218 42 180 15 '' from "" 100            ; string to Rep
  124. gadhelp 'Enter string to search for and replace'
  125. gadid 30
  126. setgad rep.gc 31 on ; goto next gadget
  127.  
  128. XTEXTIN 218 69 180 15 '' to "" 100              ; Rep with this
  129. gadhelp 'Enter string with which to replace the above'
  130. gadid 31
  131. setgad rep.gc 30 on
  132.  
  133. XCYCLER 218 86 180 14 "" ci
  134. gadhelp 'Search mode'
  135. cstr "Case Sensitive"   ""
  136. cstr "Case Insensitive" I
  137.  
  138.  
  139. ; =================================================================
  140.  
  141. ;               Save to a different dir
  142.  
  143. ; =================================================================
  144. ; --- Dir to save file in. If this is the same dir as the file being
  145. ; --- converted, then the file will be overwriten.
  146.  
  147. XCHECKBOX 372 115 26 11 "" savetodir ON OFF ON
  148. gadhelp 'Check to copy altered files to other dir - Requester will open..'
  149. if $savetodir == ON
  150.    setgad rep.gc 20 on
  151.    ReqFile -1 -1 300 200 "Choose destination:" DIR todir ram:
  152.    update rep.gc 20 $todir
  153. else
  154.    setgad rep.gc 20 off
  155. endif
  156.  
  157. XTEXTIN 218 127 180 15 '' todir "Ram:" 100
  158. gadhelp 'Altered files will be copied to this dir'
  159. gadid 20
  160.  
  161.  
  162. ; =================================================================
  163.  
  164. ;                       Do it.
  165.  
  166. ; =================================================================
  167.  
  168. XBUTTON 218 169 90 14 Start
  169. gadhelp 'Start replacing'
  170. gadid 100
  171.  
  172. ; --- check that we have all the parameters we need
  173. lvuse rep.gc 1
  174. lvmulti first
  175. if $file = ""
  176.    update rep.gc 2 "No file chosen."
  177.    stop
  178. endif
  179. if $from = ""
  180.    update rep.gc 2 'No "From" defined!'
  181.    stop
  182. endif
  183. if $to = ""
  184.    update rep.gc 2 'No "To" defined!'
  185.    stop
  186. endif
  187.  
  188. ; --- get dest dir, if defined, and make dest name..
  189. destfile = ""
  190. if $savetodir == ON
  191. and $todir > " "
  192.    extract file FILE fname
  193.    dest = $todir
  194.    joinfile $dest $fname destfile
  195. endif
  196. update rep.gc 2 '$file'
  197.  
  198. ; --- launch it..
  199. setgad rep.gc 100 off
  200. flag = 0
  201. launch 5 'Rep $file $from $to $destfile $ci'
  202.  
  203.  
  204. ; --- Use of the launch command will allow the other GUIs running on
  205. ; --- this instance of Gui4Cli to go about their business normally
  206. ; --- Then when this file is finished ...
  207.  
  208. xOnReturn 5
  209. ; --- note our arrival..
  210. update rep.gc 2 'OK - $file'
  211. lvuse rep.gc 1
  212. lvmulti OFF
  213.  
  214. ; --- check if we've already been told to stop..
  215. if $flag != 0
  216.    setgad rep.gc 100 on
  217.    stop
  218. endif
  219.  
  220. ; --- do next file
  221. lvmulti next
  222. if $file = ""          ; no more files
  223.    if $todir > " "
  224.       lvdir #$todir
  225.       setwintitle rep.gc '$$lv.dir'
  226.    else
  227.       lvdir refresh
  228.    endif
  229.    setgad rep.gc 100 on
  230.    stop
  231. endif
  232. if $savetodir == ON
  233. and $todir > " "
  234.    extract file FILE fname
  235.    dest = $todir
  236.    joinfile $dest $fname destfile
  237. endif
  238. update rep.gc 2 '$file'
  239. launch 5 'Rep $file $from $to $destfile $ci'
  240.  
  241.  
  242. ; =================================================================
  243.  
  244. ;                       Cancel & text display
  245.  
  246. ; =================================================================
  247.  
  248. XBUTTON 308 169 90 14 Stop
  249. gadhelp 'Abort replacing'
  250. breaktask Rep C
  251. setvar flag 1
  252.  
  253. xonfail ; everybody's human..
  254. setgad rep.gc 100 on
  255. update rep.gc 2 '** Error **'
  256.  
  257. ; --- a text display, telling you what's going on.
  258.  
  259. TEXT 218 154 180 14 Waiting.. 100 BOX
  260. gadid 2
  261.  
  262.  
  263.